<?php
require_once 'libs/auth.class.php';
require_once 'libs/mysql.class.php';

$conn = new Mysql();
$auth = new Auth();

if ( !$auth->is_connected() ) {
	header('Location: login.php');
	exit();
}

require_once 'libs/Twig/Autoloader.php';
Twig_Autoloader::register();

$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, array(
		/*'cache' => '/path/to/compilation_cache',*/
));

$tplVars = array();

$tplVars['breadcrumb'][] = array(
        'caption' => 'Dashboard',
        'href' => 'index.php',
        'curr' => false,
    );

$tplVars['breadcrumb'][] = array(
		'caption' => 'Cabinet',
		'href' => 'cabinet.php',
		'curr' => false,
);

$tplVars['breadcrumb'][] = array(
		'caption' => 'New',
		'href' => 'cabinet.php',
		'curr' => true,
);

$tplVars['jsFiles'] = array(
	'bootstrap/js/jquery.min.js',
	'bootstrap/js/jquery.ui.custom.js',
    'bootstrap/js/bootstrap.min.js',
    'bootstrap/js/jquery.uniform.js',
    'bootstrap/js/jquery.dataTables.min.js',
    'bootstrap/js/select2.min.js',
	'bootstrap/js/unicorn.js',
	'bootstrap/js/unicorn.tables.js',
);

$tableName = 'cabinet';
$tplVars['tableName'] = $tableName;
$sql = $conn->BuildSQLSelect($tableName);

$array = $conn->QueryArray($sql, MYSQL_ASSOC);

$tplVars['columns'] = $conn->GetColumnNames($tableName);
$tplVars['rows'] = $conn->QueryArray($sql, MYSQL_ASSOC);

echo $twig->render('cabinet.twig', $tplVars);